import React, { Component } from 'react';
// import IceContainer from '@icedesign/container';
import { Nav } from '@icedesign/base';
import { Link, withRouter } from 'react-router-dom';
import './ToolsNav.scss';

const { Item } = Nav;

@withRouter
export default class ToolsNav extends Component {
  static displayName = 'TabTable';

  static propTypes = {};

  static defaultProps = {};

  constructor(props) {
    super(props);
    // console.log("secondnav",props)
    this.state = {
      tabs: [],
      tabName:localStorage.getItem("market")==="SZ" ? "互动易统计" : "E互动统计",
      activeKey: 1,
    };
  }

  componentDidMount() {
    if(this.GetUrlParam("sid")){
      this.setState({
        activeKey:this.GetUrlParam("sid")
      })
    }
    // console.log("GetUrlParam-sid",this.GetUrlParam("sid"))
  }

  GetUrlParam(paraName) {
  　var url = document.location.toString();
  　var arrObj = url.split("?");
  　　　if (arrObj.length > 1) {
  　　　　　var arrPara = arrObj[1].split("&");
  　　　　　var arr;
  　　　　　for (var i = 0; i < arrPara.length; i++) {
  　　　　　　　arr = arrPara[i].split("=");
  　　　　　　　if (arr != null && arr[0] == paraName) {
  　　　　　　　　　return arr[1];
  　　　　　　　}
  　　　　　}
  　　　　　return "";
  　　　}
  　　　else { return ""; }
  }

  handleChange = (key) => {
    // console.log("key",key)
    // localStorage.setItem("sid",key)
    // this.setState({
    //   activeKey: key,
    // });
    if(key==0){
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2/#/tools/marketAnalysis?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key==1){
      // this.props.history.push("/")
    }else if(key==2){
      window.location.href = `${global.constants.LOCALHOST}website/list?secu_code=${this.GetUrlParam("secu_code")}`
    }
  };

  render() {
    return (
      <div className="second-menu">
      <Nav 
        direction="hoz"
        prefix="second"
        // selectMode="multiple"
        defaultSelectedKeys={["1"]}
        // selectedKeys={[`${this.state.activeKey}`]}
        onSelect={this.handleChange.bind(this)}
      >
        <Item prefix="second-" key={0}>
          融资融券统计与查询
        </Item>
        
        <Item prefix="second-" key={1}>
          {this.state.tabName}
        </Item>

        <Item prefix="second-" key={2}>
          常用网站
        </Item>
      </Nav>
      </div>
    );
  }
}

